//
//  dateViewController.m
//  Wtracker
//
//  Created by Anna on 6/29/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "dateViewController.h"
#import "WtrackerAppDelegate.h"

#define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]


@implementation dateViewController

@synthesize datePicker,dateFormatter;

- (void)viewDidLoad {
    [super viewDidLoad];
	
	self.navigationItem.title = @"Log Date";
	self.navigationItem.rightBarButtonItem = BARBUTTON(@"Save", @selector(saveDate));
	
	self.dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [self.dateFormatter setDateStyle:NSDateFormatterShortStyle];
    [self.dateFormatter setTimeStyle:NSDateFormatterNoStyle];
	
	NSDate *today = [NSDate date];
	[datePicker setDate:today animated:YES];

}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (IBAction)saveDate{
	// do the actual saving
	
	NSString *logDate = [self.dateFormatter stringFromDate:self.datePicker.date];
	NSLog(@"the logdate: %@", logDate);
	/* push dateStr to app dele */
	WtrackerAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
	[appDelegate loadMySettings];
	appDelegate.tmpDate = logDate;
	
	
	[self.navigationController popViewControllerAnimated:YES];
	
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[datePicker release];
	[dateFormatter release];
    [super dealloc];
}


@end
